<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<!DOCTYPE html >
<html>
	<head>
		<%@ include file="/common/taglibs.jsp"%>
		<title>sinlog</title>
	</head>
	<body>
		<div class="mainContent">
			<div class="searDiv">
				<table class="searTb">
					<tr>
						<td><table>
							<tr>
								<td width="100" align="right"><label>应用名称：</label></td>
								<td><input id="q_appName" type="text" /></td>
							</tr>
						</table></td>
						<td width="200"><a href="javascript:doQuery();" class="button blue">查询</a></td>
					</tr>
				</table>
			</div>
			<div class="dgDiv">
				<table id="dg"></table> 
			</div>
		</div>
<script type="text/javascript">
	$(document).ready(function(){
		$('#dg').datagrid({   
		    url:'${ctx}/app!list.action',   
		    pagination:true,
		    height: getDgH('dgDiv') - 55,
		    pageSize:30,
		    pageList:[30,60,100,200], 
		    columns:[[   
				{checkbox:true,field:'ck'},
		        {title:'应用名',field:'appName',width:150},
		        {title:'KEY',field:'appKey',width:150},
		        {title:'SECRET',field:'appSecret',width:300},
		        {title:'创建用户',field:'userName',width:100},
		        {title:'读控制',field:'rlimit',width:100},
		        {title:'写控制',field:'wlimit',width:100},
		        {field:'editor',title:'操作',width:100,align:'center',formatter:function(value,row,index){
					var ed = '<a class="dicon icon-search" title="详细" onclick=goView(\''+row.appId+'\')></a>&nbsp;';
					ed += '<a class="dicon icon-edit" title="修改" onclick=goEdit(\''+row.appId+'\')></a>&nbsp;';
					ed += '<a class="dicon icon-remove" title="删除" onclick=goDelete('+null+',\''+row.appId+'\')></a>';
					return ed;
				}}
		    ]],
		    toolbar:[{
		    	text:'新增',  
				iconCls: 'icon-add',
				handler: goAdd
			},{
		    	text:'删除',  
				iconCls: 'icon-remove',
				handler: goDelete
			}],
		    queryParams:{
		       'q_appName_eq_s': $('#q_appName').val()
		   	},
		   	onDblClickRow:function(rowIndex, rowData){
		   		goEdit(rowData.appId);
		   	}
		}); 
	});
	function doQuery(){
		var queryParams = $('#dg').datagrid('options').queryParams;
	    queryParams["q_appName_eq_s"] = $('#q_appName').val();

	    $('#dg').datagrid('options').pageNumber = 1;
	    var p = $('#dg').datagrid('getPager');
	    if (p){
	        $(p).pagination({
	           pageNumber:1,
	           pageSize:30
	        });
	        queryParams["rows"] = 30;
	        queryParams["page"] = 1;
	    }
	    $('#dg').datagrid('reload');
	}
	function goAdd(){
		openMenu('应用管理-新增应用','${ctx}/app!add.action');
	}
	
	function goEdit(id){
		openMenu('应用管理-修改应用','${ctx}/app!edit.action?app.appId='+id);
	}
	function goView(id){
		openMenu('应用管理-查看应用','${ctx}/app!view.action?app.appId='+id);
	}
	function goDelete(event,id){
		var ids = '';
		if(id){
			ids = id;
		}else{
			var ids = getCkIds('dg','appId');
		}
		if(ids == ''){
			$.messager.alert('系统提示','请选择要操作的记录！','info');
		}else{
			$.messager.confirm('系统提示','确定执行该操作？',function(r){
				if(r){
					wait();
					Util.doAjaxPost('${ctx}/app!delete.action',{ids:ids},function(text){
						uwait();
						var ret = jQuery.parseJSON(text);
						if(ret.success){
							doQuery();
						}else{
							$.messager.alert('系统提示','操作失败！','error');
						}
					});
				}
			});
		}
	}
</script>
	</body>
</html>